package org.cangkuguanli.dongbozhibookstore.controller;

import org.cangkuguanli.dongbozhibookstore.bean.Book;
import org.cangkuguanli.dongbozhibookstore.mapper.BookMapper;
import org.cangkuguanli.dongbozhibookstore.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    private BookMapper bookMapper;

    @RequestMapping("/fresh_book")
    public JsonResult findByFreshBook() {
        List<Book> list = bookMapper.findByFreshBook();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }
    @RequestMapping("/fresh_book_more")
    public JsonResult findByFreshBookMore() {
        List<Book> list = bookMapper.findByFreshBookMore();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }


    @RequestMapping("/lower_book")
    public JsonResult findByLowerBook(){
        List<Book> list = bookMapper.findByLowerBook();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }

    @RequestMapping("/lower_book_more")
    public JsonResult findByLowerBookMore(){
        List<Book> list = bookMapper.findByLowerBookMore();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }

    /**
     * 按名字查询
     * @param name
     * @return
     */
    @RequestMapping("/find_book_name")
    public JsonResult findByLikeName(String name){
        List<Book> list = bookMapper.findByLikeName("%" + name + "%");
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }
}
